﻿// 1.1.6.17. Write a program that calculates the greatest common divisor (GCD) of given two numbers.
// Use the Euclidean algorithm (find it in Internet).

// pretty clear explanation of the algorithm: http://en.wikipedia.org/wiki/Euclidean_algorithm#Worked_example
using System;

class EuclideanAlgorithmTry
{
    static void Main()
    {
        int firstUserInput = int.Parse(Console.ReadLine());
        int secondUserInput = int.Parse(Console.ReadLine());
        if (secondUserInput > firstUserInput)   // I ensure that the firstUserInput will be always the greater one variable
        {
            firstUserInput += secondUserInput;
            secondUserInput = firstUserInput - secondUserInput;
            firstUserInput -= secondUserInput;
        }

        for (int i = 0, tempVariable = 0; i < int.MaxValue; i++)
        {
            tempVariable = secondUserInput;
            secondUserInput = firstUserInput - ((firstUserInput / secondUserInput) * secondUserInput);
            firstUserInput = tempVariable;
            if (secondUserInput == 0)
            {
                Console.WriteLine(firstUserInput);
                break;
            }
        }
    }
}